class Approval < ActiveRecord::Base
  belongs_to            :user
  belongs_to            :photo
  belongs_to            :video
  belongs_to            :gallery
  
  validates_presence_of :gallery
  validates_presence_of :user
  validate              :must_have_either_photo_or_video
  validate              :must_have_only_a_photo_or_video
  
  def must_have_either_photo_or_video
    self.errors.add("An approval must be for either a photo or a video") unless self.photo or self.video
  end
  
  def must_have_only_a_photo_or_video
    self.errors.add("An approval must be for only either a photo or a video") if self.photo and self.video
  end
  
  def decline!
    self.update_attributes!(:declined => true, :approved => false)
  end
  
  def approve!
    self.update_attributes!(:declined => false, :approved => true)
  end
  
  def for_video?
    self.video ? true : false
  end
  
  def for_photo?
    self.photo ? true : false
  end
end
